home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / language / harvest.cpt / Harvest C / Tcl 6.2 / tclUnix.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-13  |  8.2 KB  |  335 lines

  1. /*
  2.  * tclUnix.h --
  3.  *
  4.  *    This file reads in UNIX-related header files and sets up
  5.  *    UNIX-related macros for Tcl's UNIX core.  It should be the
  6.  *    only file that contains #ifdefs to handle different flavors
  7.  *    of UNIX.  This file sets up the union of all UNIX-related
  8.  *    things needed by any of the Tcl core files.  This file
  9.  *    depends on configuration #defines in tclConfig.h
  10.  *
  11.  *    The material in this file was originally contributed by
  12.  *    Karl Lehenbauer, Mark Diekhans and Peter da Silva.
  13.  *
  14.  * Copyright 1991 Regents of the University of California
  15.  * Permission to use, copy, modify, and distribute this
  16.  * software and its documentation for any purpose and without
  17.  * fee is hereby granted, provided that this copyright
  18.  * notice appears in all copies.  The University of California
  19.  * makes no representations about the suitability of this
  20.  * software for any purpose.  It is provided "as is" without
  21.  * express or implied warranty.
  22.  *
  23.  * $Header: /user6/ouster/tcl/RCS/tclUnix.h,v 1.24 91/12/06 15:32:36 ouster Exp $ SPRITE (Berkeley)
  24.  */
  25.  
  26. #ifndef _TCLUNIX
  27. #define _TCLUNIX
  28.  
  29. /*
  30.  * The following #defines are used to distinguish between different
  31.  * UNIX systems.  These #defines are normally set by the "config" script
  32.  * based on information it gets by looking in the include and library
  33.  * areas.  The defaults below are for BSD-based systems like SunOS
  34.  * or Ultrix.
  35.  *
  36.  * TCL_GETTOD -            1 means there exists a library procedure
  37.  *                "gettimeofday" (e.g. BSD systems).  0 means
  38.  *                have to use "times" instead.
  39.  * TCL_GETWD -            1 means there exists a library procedure
  40.  *                "getwd" (e.g. BSD systems).  0 means
  41.  *                have to use "getcwd" instead.
  42.  * TCL_SYS_ERRLIST -        1 means that the array sys_errlist is
  43.  *                defined as part of the C library.
  44.  * TCL_SYS_TIME_H -        1 means there exists an include file
  45.  *                <sys/time.h> (e.g. BSD derivatives).
  46.  * TCL_SYS_WAIT_H -        1 means there exists an include file
  47.  *                <sys/wait.h> that defines constants related
  48.  *                to the results of "wait".
  49.  * TCL_UNION_WAIT -        1 means that the "wait" system call returns
  50.  *                a structure of type "union wait" (e.g. BSD
  51.  *                systems).  0 means "wait" returns an int
  52.  *                (e.g. System V and POSIX).
  53.  * TCL_PID_T -            1 means that <sys/types> defines the type
  54.  *                pid_t.  0 means that it doesn't.
  55.  * TCL_UID_T -            1 means that <sys/types> defines the type
  56.  *                uid_t.  0 means that it doesn't.
  57.  */
  58.  
  59. #define TCL_GETTOD 1
  60. #define TCL_GETWD 1
  61. #define TCL_SYS_ERRLIST 1
  62. #define TCL_SYS_TIME_H 1
  63. #define TCL_SYS_WAIT_H 1
  64. #define TCL_UNION_WAIT 1
  65. #define TCL_PID_T 1
  66. #define TCL_UID_T 1
  67.  
  68. #ifdef macintosh
  69.  
  70. #include <errno.h>
  71. #include <fcntl.h>
  72. #include <limits.h>
  73. /* #include <pwd.h>            */
  74. #include <signal.h>
  75. /* #include <sys/param.h>    */
  76. /* #include <sys/types.h>    */
  77. /* #include <dirent.h>        */
  78. /* #include <sys/file.h>    */
  79. #include "stat.h"
  80. #include <time.h>
  81.  
  82. #else
  83.  
  84. #include <errno.h>
  85. #include <fcntl.h>
  86. #include <limits.h>
  87. #include <pwd.h>
  88. #include <signal.h>
  89. #include <sys/param.h>
  90. #include <sys/types.h>
  91. #include <dirent.h>
  92. #include <sys/file.h>
  93. #include <sys/stat.h>
  94. #if TCL_SYS_TIME_H
  95. #   include <sys/time.h>
  96. #else
  97. #   include <time.h>
  98. #endif
  99. #if TCL_SYS_WAIT_H
  100. #   include <sys/wait.h>
  101. #endif
  102.  
  103. #endif
  104.  
  105. /*
  106.  * Not all systems declare the errno variable in errno.h. so this
  107.  * file does it explicitly.  The list of system error messages also
  108.  * isn't generally declared in a header file anywhere.
  109.  */
  110.  
  111. extern int errno;
  112. extern int sys_nerr;
  113. extern char *sys_errlist[];
  114.  
  115. /*
  116.  * The type of the status returned by wait varies from UNIX system
  117.  * to UNIX system.  The macro below defines it:
  118.  */
  119.  
  120. #if TCL_UNION_WAIT
  121. #   define WAIT_STATUS_TYPE union wait
  122. #else
  123. #   define WAIT_STATUS_TYPE int
  124. #endif
  125.  
  126. /*
  127.  * Supply definitions for macros to query wait status, if not already
  128.  * defined in header files above.
  129.  */
  130.  
  131. #ifndef WIFEXITED
  132. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  133. #endif
  134.  
  135. #ifndef WEXITSTATUS
  136. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  137. #endif
  138.  
  139. #ifndef WIFSIGNALED
  140. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  141. #endif
  142.  
  143. #ifndef WTERMSIG
  144. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  145. #endif
  146.  
  147. #ifndef WIFSTOPPED
  148. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  149. #endif
  150.  
  151. #ifndef WSTOPSIG
  152. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  153. #endif
  154.  
  155. /*
  156.  * Supply macros for seek offsets, if they're not already provided by
  157.  * an include file.
  158.  */
  159.  
  160. #ifndef SEEK_SET
  161. #   define SEEK_SET 0
  162. #endif
  163.  
  164. #ifndef SEEK_CUR
  165. #   define SEEK_CUR 1
  166. #endif
  167.  
  168. #ifndef SEEK_END
  169. #   define SEEK_END 2
  170. #endif
  171.  
  172. /*
  173.  * The stuff below is needed by the "time" command.  If this
  174.  * system has no gettimeofday call, then must use times and the
  175.  * CLK_TCK #define (from sys/param.h) to compute elapsed time.
  176.  * Unfortunately, some systems only have HZ and no CLK_TCK, and
  177.  * some might not even have HZ.
  178.  */
  179.  
  180. #if ! TCL_GETTOD
  181. #   include <sys/times.h>
  182. #   include <sys/param.h>
  183. #   ifndef CLK_TCK
  184. #       ifdef HZ
  185. #           define CLK_TCK HZ
  186. #       else
  187. #           define CLK_TCK 60
  188. #       endif
  189. #   endif
  190. #endif
  191.  
  192. /*
  193.  * Define access mode constants if they aren't already defined.
  194.  */
  195.  
  196. #ifndef F_OK
  197. #    define F_OK 00
  198. #endif
  199. #ifndef X_OK
  200. #    define X_OK 01
  201. #endif
  202. #ifndef W_OK
  203. #    define W_OK 02
  204. #endif
  205. #ifndef R_OK
  206. #    define R_OK 04
  207. #endif
  208.  
  209. /*
  210.  * On systems without symbolic links (i.e. S_IFLNK isn't defined)
  211.  * define "lstat" to use "stat" instead.
  212.  */
  213.  
  214. #ifdef NEVER_DEFINED
  215. #ifndef S_IFLNK
  216. #   define lstat stat
  217. #endif
  218. #endif
  219.  
  220. /*
  221.  * Define macros to query file type bits, if they're not already
  222.  * defined.
  223.  */
  224.  
  225. #ifndef S_ISREG
  226. #   ifdef S_IFREG
  227. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  228. #   else
  229. #       define S_ISREG(m) 0
  230. #   endif
  231. # endif
  232. #ifndef S_ISDIR
  233. #   ifdef S_IFDIR
  234. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  235. #   else
  236. #       define S_ISDIR(m) 0
  237. #   endif
  238. # endif
  239. #ifndef S_ISCHR
  240. #   ifdef S_IFCHR
  241. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  242. #   else
  243. #       define S_ISCHR(m) 0
  244. #   endif
  245. # endif
  246. #ifndef S_ISBLK
  247. #   ifdef S_IFBLK
  248. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  249. #   else
  250. #       define S_ISBLK(m) 0
  251. #   endif
  252. # endif
  253. #ifndef S_ISFIFO
  254. #   ifdef S_IFIFO
  255. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  256. #   else
  257. #       define S_ISFIFO(m) 0
  258. #   endif
  259. # endif
  260. #ifndef S_ISLNK
  261. #   ifdef S_IFLNK
  262. #       define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  263. #   else
  264. #       define S_ISLNK(m) 0
  265. #   endif
  266. # endif
  267. #ifndef S_ISSOCK
  268. #   ifdef S_IFSOCK
  269. #       define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  270. #   else
  271. #       define S_ISSOCK(m) 0
  272. #   endif
  273. # endif
  274.  
  275. /*
  276.  * Make sure that MAXPATHLEN is defined.
  277.  */
  278.  
  279. #ifndef MAXPATHLEN
  280. #   ifdef _POSIX_PATH_MAX
  281. #       define MAXPATHLEN _POSIX_PATH_MAX
  282. #   else
  283. #       define MAXPATHLEN 2048
  284. #   endif
  285. #endif
  286.  
  287. /*
  288.  * Define pid_t and uid_t if they're not already defined.
  289.  */
  290.  
  291. #if ! TCL_PID_T
  292. #   define pid_t int
  293. #endif
  294. #if ! TCL_UID_T
  295. #   define uid_t int
  296. #endif
  297.  
  298. /*
  299.  * Variables provided by the C library:
  300.  */
  301.  
  302. extern char **environ;
  303.  
  304. /*
  305.  * Library procedures used by Tcl but not declared in a header file:
  306.  */
  307.  
  308. extern int    access       _ANSI_ARGS_((CONST char *path, int mode));
  309. extern long    lseek       _ANSI_ARGS_((int fd, int offset, int whence));
  310. extern int    dup2       _ANSI_ARGS_((int src, int dst));
  311. extern int    open       _ANSI_ARGS_((CONST char *path, int flags, ...));
  312. extern int    read       _ANSI_ARGS_((int fd, char *buf, int numBytes));
  313. extern int    write       _ANSI_ARGS_((int fd, char *buf, int numBytes));
  314. extern int    close       _ANSI_ARGS_((int fd));
  315. extern int    unlink        _ANSI_ARGS_((CONST char *path));
  316.  
  317. #ifndef macintosh
  318.  
  319. extern int    chdir       _ANSI_ARGS_((CONST char *path));
  320. extern int    execvp       _ANSI_ARGS_((CONST char *name, char **argv));
  321. extern void    _exit        _ANSI_ARGS_((int status));
  322. extern pid_t    fork       _ANSI_ARGS_((void));
  323. extern uid_t    geteuid       _ANSI_ARGS_((void));
  324. extern pid_t    getpid       _ANSI_ARGS_((void));
  325. extern char *    getcwd        _ANSI_ARGS_((char *buffer, int size));
  326. extern char *    getwd         _ANSI_ARGS_((char *buffer));
  327. extern int    kill       _ANSI_ARGS_((pid_t pid, int sig));
  328. extern char *    mktemp       _ANSI_ARGS_((char *template));
  329. extern int    pipe       _ANSI_ARGS_((int *fdPtr));
  330. extern int    readlink   _ANSI_ARGS_((CONST char *path, char *buf, int size));
  331.  
  332. #endif /* ! macintosh */
  333.  
  334. #endif /* _TCLUNIX */
  335.